package com.renwei.yunlong.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.pager.ProblemAnnexPager;
import com.renwei.yunlong.pager.ProblemDetailsPager;
import com.renwei.yunlong.pager.ProblemHistoryPager;
import com.renwei.yunlong.pager.ProblemRecordingPager;
import com.renwei.yunlong.pager.ProblemRelatedPager;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;
import com.zyf.fwms.commonlibrary.utils.CommonUtils;
import com.zyf.fwms.commonlibrary.utils.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.leefeng.promptlibrary.PromptDialog;

/**
 * 问题信息--页面
 * <p>
 * Created by Administrator on 2017/8/28.
 */

public class ProblemInformationActivity extends AppCompatActivity implements View.OnClickListener{

    @Bind(R.id.tab_layout)
    TabLayout mTabLayout;
    @Bind(R.id.v_pager)
    ViewPager mViewPager;
    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;

    private List<Fragment> list;
    private String[] titles = {"过程", "详情", "附件", "相关", "记录", "历史",};

    ProblemInformationAdapter adapter;

    PromptDialog promptDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_problem_information);
        ButterKnife.bind(this);

        StatusBarUtil.setColor(this, CommonUtils.getColor(this, R.color.title_color), 0);

        //屏幕自适配
        AutoUtils.setSize(this, false, 720, 1280);
        AutoUtils.auto(this);

        initData();
    }

    private void initData() {
        ivBack.setVisibility(View.VISIBLE);
        tvTitle.setText("问题信息");
        ivBack.setOnClickListener(this);

        //页面，数据源
        list = new ArrayList<>();
        list.add(new ProblemRecordingPager());
        list.add(new ProblemDetailsPager());
        list.add(new ProblemAnnexPager());
        list.add(new ProblemRelatedPager());
        list.add(new ProblemRecordingPager());
        list.add(new ProblemHistoryPager());

        //ViewPager的适配器
        adapter = new ProblemInformationAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(adapter);

        //绑定
        mTabLayout.setupWithViewPager(mViewPager);

        promptDialog = new PromptDialog(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            default:
                break;
        }
    }

    class ProblemInformationAdapter extends FragmentStatePagerAdapter {

        public ProblemInformationAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        //重写这个方法，将设置每个Tab的标题
        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }
}
